/*
 * ListOperatorExpression.java
 *
 * Created on March 1, 2007, 10:17 PM
 *
 * (C) R. Alexander Milowski alex@milowski.com
 */

package com.smallx.xpath.parser;

import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author R. Alexander Milowski
 */
public class ListOfExpressions extends ArrayList<Expression> implements Expression,List<Expression> {

   Operator operator;
   
   /** Creates a new instance of ListOperatorExpression */
   public ListOfExpressions(Operator op) {
      this.operator = op;
   }
   
   public ListOfExpressions(Operator op,Expression child) {
      this.operator = op;
      this.add(child);
   }
   
   public Operator getOperator() {
      return operator;
   }
   
   public String toString() {
      return "("+operator+" "+toString(this)+" )";
   }
   
   public static String toString(List<Expression> exprs) {
      StringBuilder builder = new StringBuilder();
      for (Expression e: exprs) {
         boolean first = builder.length()==0;
         if (!first) {
            builder.append(" ");
         }
         builder.append(e.toString());
      }
      return builder.toString();
   }
   
}
